import { reactive } from "vue";
import type { FormRules } from "element-plus";
import { isPhone } from "@pureadmin/utils";

/** 自定义表单规则校验 */
export const formRules = reactive(<FormRules>{
	isVat: [{ required: true, message: "是否增值税发票为必填项", trigger: "change" }],
	invoiceTitle: [{ required: true, message: "发票抬头名称为必填项", trigger: "blur" }],
	content: [{ required: true, message: "发票抬头内容为必填项", trigger: "blur" }],
	amount: [{ required: true, message: "发票金额为必填项", trigger: "blur" }],
	taxNo: [{ required: true, message: "发票税号为必填项", trigger: "blur" }],
	tax: [{ required: true, message: "开票税金为必填项", trigger: "blur" }],
	companyName: [{ required: true, message: "公司名称为必填项", trigger: "blur" }],
	companyAddress: [{ required: true, message: "公司地址为必填项", trigger: "blur" }],
	telephone: [{ required: true, message: "联系电话为必填项", trigger: "blur" },
	{
		validator: (rule, value, callback) => {
			if (value === "") {
				callback();
			} else if (!isPhone(value)) {
				callback(new Error("请输入正确的手机号码格式"));
			} else {
				callback();
			}
		},
		trigger: "blur"
	}],
	bankName: [{ required: true, message: "开户银行为必填项", trigger: "blur" }],
	bankAccount: [{ required: true, message: "银行帐号为必填项", trigger: "blur" }],
  projectId: [{ required: true, message: "项目列表为必填项", trigger: "change" }],
  taskId: [{ required: true, message: "任务阶段为必填项", trigger: "change" }],
});
